package com.ruoyi.web.controller.purchase;

import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.purchase.pojo.PurchaseApplyMaterial;
import com.ruoyi.purchase.service.PurchaseApplyMaterialService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;

import java.util.List;

/**
 * 采购申请清单Controller
 *
 * @author ruoyi
 * @date 2024-10-25
 */
@RestController
@RequestMapping("/purchase/material")
public class PurchaseApplyMaterialController extends BaseController{
    @Autowired
    private PurchaseApplyMaterialService purchaseApplyMaterialService;
    /**
     * 查询采购申请清单列表
     */
    @PreAuthorize("@ss.hasPermi('purchase:material:list')")
    @GetMapping("/list")
    public TableDataInfo list(PurchaseApplyMaterial purchaseApplyMaterial){
        startPage();
        List<PurchaseApplyMaterial> list = purchaseApplyMaterialService.selectPurchaseApplyMaterialList(purchaseApplyMaterial);
        return getDataTable(list);
    }


    /**
     * 导出采购申请清单列表
     */
    @PreAuthorize("@ss.hasPermi('purchase:material:export')")
    @Log(title = "采购申请清单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PurchaseApplyMaterial purchaseApplyMaterial)
    {
        List<PurchaseApplyMaterial> list = purchaseApplyMaterialService.selectPurchaseApplyMaterialList(purchaseApplyMaterial);
        ExcelUtil<PurchaseApplyMaterial> util = new ExcelUtil<PurchaseApplyMaterial>(PurchaseApplyMaterial.class);
        util.exportExcel(response, list, "采购申请清单数据");
    }

    /**
     * 获取采购申请清单详细信息
     */
    @PreAuthorize("@ss.hasPermi('purchase:material:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(purchaseApplyMaterialService.selectPurchaseApplyMaterialById(id));
    }

    @GetMapping(value = "/getSelectPurchaseApply/{id}")
    public AjaxResult selectPurchaseApply(@PathVariable("id") Integer id)
    {
        return success(purchaseApplyMaterialService.selectPurchaseApply(id));
    }

    /**
     * 新增采购申请清单
     */
    @PreAuthorize("@ss.hasPermi('purchase:material:add')")
    @Log(title = "采购申请清单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PurchaseApplyMaterial purchaseApplyMaterial)
    {
        return toAjax(purchaseApplyMaterialService.insertPurchaseApplyMaterial(purchaseApplyMaterial));
    }

    /**
     * 修改采购申请清单
     */
    @Log(title = "采购申请清单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PurchaseApplyMaterial purchaseApplyMaterial)
    {
        return toAjax(purchaseApplyMaterialService.updatePurchaseApplyMaterial(purchaseApplyMaterial));
    }

    /**
     * 删除采购申请清单
     */
    @Log(title = "采购申请清单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(purchaseApplyMaterialService.deletePurchaseApplyMaterialByIds(ids));
    }
    /**
     * 删除采购申请清单
     */
    @Log(title = "采购申请清单", businessType = BusinessType.DELETE)
    @DeleteMapping("delPurchaseApplyId/{purchaseApplyId}")
    public AjaxResult deleteByApplyId(@PathVariable Integer purchaseApplyId){
        return toAjax(purchaseApplyMaterialService.deletePurchaseApplyMaterialByApplyId(purchaseApplyId));
    }
}